package com.rongshu.view.penpal.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.rongshu.R;
import com.rongshu.utils.Constant;
import com.rongshu.view.base.AdapterListener;
import com.rongshu.view.home.activity.PreviewImgActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * created by zhengweis on 2019/2/12.
 * description：帖子插图
 */
public class PostInsertImgAdapter extends RecyclerView.Adapter<PostInsertImgAdapter.ViewHolder> {

    protected Context context;
    protected ArrayList<String> list;

    public PostInsertImgAdapter(Context context, ArrayList<String> list) {
        this.list = list;
        this.context = context;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(context).inflate(R.layout.adapter_post_insert_image, viewGroup, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull final ViewHolder viewHolder, final int position) {
        Glide.with(context).load(list.get(position)).into(viewHolder.postInsertImg);
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, PreviewImgActivity.class);
                intent.putExtra(Constant.INTENT_MESSAGE, list.get(position));
                intent.putStringArrayListExtra(Constant.INTENT_DATA, list);
                context.startActivity(intent);
            }
        });
    }


    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.post_insert_image)
        ImageView postInsertImg;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }


}